﻿using System;
using System.Windows;
using System.Windows.Controls;
using DL.PhotoCollage.Core;
using DL.PhotoCollage.UI.StandAlone.Presentation;

namespace DL.PhotoCollage.UI.StandAlone.Views
{
    public partial class SetupView : Window
    {
        internal SetupView(SetupPresenter presenter)
        {
            this.DataContext = presenter;
            this.InitializeComponent();
        }

        internal SetupPresenter Presenter
        {
            get { return this.DataContext as SetupPresenter; }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.SetSpeedComboBoxValue();
        }

        private void DirectorySelectButton_Click(object sender, RoutedEventArgs e)
        {
            this.Presenter.RequestDirectoryFromUser();
            this.DirectoryTextBox.Text = this.Presenter.Controller.Configuration.Directory;
        }

        private void SpeedComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string selectedValue = ((ComboBoxItem)this.SpeedComboBox.SelectedItem).Content.ToString().ToLower();

            switch (selectedValue)
            {
                case "slow":
                    this.Presenter.Controller.Configuration.Speed = ScreensaverSpeed.Slow;
                    break;
                case "medium":
                    this.Presenter.Controller.Configuration.Speed = ScreensaverSpeed.Medium;
                    break;
                case "fast":
                    this.Presenter.Controller.Configuration.Speed = ScreensaverSpeed.Fast;
                    break;
            }
        }

        private void SetSpeedComboBoxValue()
        {
            switch (this.Presenter.Controller.Configuration.Speed)
            {
                case ScreensaverSpeed.Slow:
                    this.SpeedComboBox.SelectedItem = this.SpeedComboBox.Items[0];
                    break;
                case ScreensaverSpeed.Medium:
                    this.SpeedComboBox.SelectedItem = this.SpeedComboBox.Items[1];
                    break;
                case ScreensaverSpeed.Fast:
                    this.SpeedComboBox.SelectedItem = this.SpeedComboBox.Items[2];
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }

        private void StartButton_Click(object sender, RoutedEventArgs e)
        {
            this.Presenter.StartCollage();
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
